<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/oauthplatform/static/css/x-admin/font.css">
    <link rel="stylesheet" href="/oauthplatform/static/css/x-admin/xadmin.css">
    <link rel="stylesheet" href="/oauthplatform/static/lib/zTree/css/zTreeStyle/zTreeStyle.css">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" id="dataForm">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-inline">
                    <input type="text" name="userName" class="layui-input" required lay-verify="required|userName" autocomplete="off" placeholder="请输入用户名" >
                </div>
                <div class="layui-form-mid layui-word-aux">必填：仅限数字与字母(不区分大小写)</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                    <input type="text" value="默认密码：hnzy1234" class="layui-input" readonly autocomplete="off" >
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">系统昵称</label>
                <div class="layui-col-md4 layui-input-inline">
                    <input type="text" name="nickName" class="layui-input" maxlength="10" required lay-verify="required" autocomplete="off" placeholder="请输入角色名称" >
                </div>
                <div class="layui-form-mid layui-word-aux">必填</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">真实姓名</label>
                <div class="layui-col-md4 layui-input-inline">
                    <input type="text" name="name" class="layui-input" maxlength="10" required lay-verify="required" autocomplete="off" placeholder="请输入角色名称" >
                </div>
                <div class="layui-form-mid layui-word-aux">必填</div>
            </div>


<#--            <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-inline">
                    <select name="isValid">
                        <option value="3">其他</option>
                        <option value="1">男</option>
                        <option value="2">女</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">出生日期</label>
                <div class="layui-input-inline">
                    <input readonly name="birthdayStr" id="birthdayStr" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">身份证号码</label>
                <div class="layui-input-inline">
                    <input type="text" name="idCard" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">联系方式</label>
                <div class="layui-input-inline">
                    <input type="text" name="phone" class="layui-input" maxlength="15">
                </div>
            </div>-->

            <div class="layui-form-item">
                <label class="layui-form-label">用户类型</label>
                <div class="layui-input-inline">
                    <select name="userType" lay-verify="required" required>
                        <option value="1">教育系统内部</option>
                        <option value="0">教育系统外部</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">是否启用</label>
                <div class="layui-input-inline">
                    <select name="isValid" lay-verify="required" required>
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">所属地市</label>
                <div class="layui-input-inline">
                    <select name="areaId" lay-search lay-verify="required" required>
                        <option value="">请选择</option>
                        <#list areaList as al>
                            <option value="${al.areaId}">${al.areaName}</option>
                        </#list>
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">必选</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">详细地址</label>
                <div class="layui-col-md6">
                    <input type="text" name="address" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">所属机构</label>
                <div class="layui-col-md6">
                    <select name="deptId" lay-search required lay-verify="required">
                        <option value="">请选择</option>
                        <#list deptList as dl>
                            <option value="${(dl.id?c)!}">${dl.deptName}</option>
                        </#list>
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">必选</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">授权</label>
                <div class="layui-input-inline" style="width: 50%;!important">
                    <div class="layui-card-body">
                        <div id="dataTables"></div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" src="/oauthplatform/static/lib/layui/layui.all.js" charset="utf-8"></script>
<script type="text/javascript" src="/oauthplatform/static/lib/jquery/jquery.3.4.1.js"></script>
<script type="text/javascript" src="/oauthplatform/static/lib/x-admin/xadmin.js"></script>
<script src="/oauthplatform/static/lib/other/html5.min.js"></script>
<script src="/oauthplatform/static/lib/other/respond.min.js"></script>
<script src="/oauthplatform/static/lib/zTree/js/jquery.ztree.core.js"></script>
<script type="application/javascript">
    var table ;

    layui.use(['table','jquery'], function(){
        table = layui.table;

        //第一个实例
        table.render({
            elem: '#dataTables'
            ,url: '/oauthplatform/awarded/list' //数据接口
            ,parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": 0, //解析接口状态
                    "msg": "", //解析提示文本
                    "count": res.length, //解析数据长度
                    "data": res //解析数据列表
                };
            },
            where:{userId:$("#userId").val()}
            ,page:false
            ,cols: [[ //表头
                {type:'checkbox',field: 'LAY_CHECKED'}
                ,{field: 'name', title: '角色名称'}
            ]]
        });
    });

    layui.use(['form','laydate'], function(){

        var form = layui.form;

        form.verify({
            userName: function(value, item){ //value：表单的值、item：表单的DOM对象
                if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){ return '用户名不能有特殊字符'; }
                if(!/^[^\s]*$/.test(value)){ return '用户名不能包含空格'; }
                if(/^\d+\d+\d$/.test(value)){ return '用户名不能全为数字'; }
            }
        });

        //监听提交
        form.on('submit(formDemo)', function(data){
            var checkStatus = table.checkStatus('dataTables'),data = checkStatus.data;
            if (data.length > 1){ layer.msg("用户授权只能择一选取"); return false; }
            var rids = '';
            if(data!=null && data.length>0){
                for(var i = 0;i<data.length;i++){
                    rids += data[i].id+',';
                }
            }
            $.ajax({
                type: "POST",//方法类型
                url: "/oauthplatform/user/save" ,//url
                data: $('#dataForm').serialize(),
                success: function (result) {

                    if(parseInt(result.code)==500){ layer.msg(result.msg); }

                    if(result.msg == "操作成功"){
                        $.ajax({
                            type: "POST",//方法类型
                            url: "/oauthplatform/awarded/save" ,//url
                            data: {rids:rids,userId:result.code},
                            success: function (result) {
                                layer.msg(result.msg);
                                if(parseInt(result.code) == 200){
                                    setTimeout(function(){ xadmin.close(); xadmin.father_reload(); }, 900);
                                }
                            },
                            error: function (result) {layer.msg("系统异常,请联系管理员");}
                        });
                    }
                },
                error: function (result) { layer.msg("系统异常,请联系管理员"); }
            });
            return false;
        });
    });
</script>

</html>